#ifndef __OLED_SPI_H
#define __OLED_SPI_H

#include "stm32f1xx_hal.h"
#include "main.h"


//??: 
//----------------------------------------------------------------
//GND    
//VCC  3.3v
//D0   PA5  (SPI1_SCK===>LCD_SCK)   ?????
//D1   PA7  (SPI1_MOSI===>LCD_MOSI) ?????
//RES  PB0  reset OLED
//DC   PB1  commond/data
//CS   PA4  OLED chip select

#define     OLED_CS_Set()       HAL_GPIO_WritePin(OLED_CS_GPIO_Port, OLED_CS_Pin, GPIO_PIN_SET);
#define     OLED_CS_Clr()       HAL_GPIO_WritePin(OLED_CS_GPIO_Port, OLED_CS_Pin, GPIO_PIN_RESET);

#define     OLED_DC_Set()       HAL_GPIO_WritePin(OLED_DC_GPIO_Port, OLED_DC_Pin, GPIO_PIN_SET);
#define     OLED_DC_Clr()       HAL_GPIO_WritePin(OLED_DC_GPIO_Port, OLED_DC_Pin, GPIO_PIN_RESET);

#define     OLED_RST_Set()      HAL_GPIO_WritePin(OLED_RES_GPIO_Port, OLED_RES_Pin, GPIO_PIN_SET);
#define     OLED_RST_Clr()      HAL_GPIO_WritePin(OLED_RES_GPIO_Port, OLED_RES_Pin, GPIO_PIN_RESET);

#define OLED_CMD  0	//???
#define OLED_DATA 1	//???
#define WHICH_SPI &hspi1
//sption from datasheet
#define	    BRIGHTNESS	  0xCF		//light
#define     X_WIDTH       128		//width
#define     Y_WIDTH       64		//length
#define		PAGE		  8			//pages
#define		MAX_CHAR_POSX X_WIDTH-6 //word width-6
#define		MAX_CHAR_POSY Y_WIDTH-6 //word length-6



void OLED_ClearPoint(uint8_t x,uint8_t y);
void OLED_ColorTurn(uint8_t i);
void OLED_DisplayTurn(uint8_t i);
void OLED_WR_Byte(uint8_t dat,uint8_t cmd);
void OLED_DisPlay_On(void);
void OLED_DisPlay_Off(void);
void OLED_Refresh(void);
void OLED_Clear(void);
void OLED_DrawPoint(uint8_t x,uint8_t y);
void OLED_DrawLine(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2);
void OLED_DrawSquare(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2);
void OLED_DrawCircle(uint8_t x,uint8_t y,uint8_t r);
void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr,uint8_t size1);
void OLED_ShowString(uint8_t x,uint8_t y,uint8_t *chr,uint8_t size1);
void OLED_ShowNum(uint8_t x,uint8_t y,uint32_t num,uint8_t len,uint8_t size1);
void OLED_ShowChinese(uint8_t x,uint8_t y,uint8_t num,uint8_t size1);
void OLED_ScrollDisplay(uint8_t num,uint8_t space);
void OLED_WR_BP(uint8_t x,uint8_t y);
void OLED_ShowPicture(uint8_t x0,uint8_t y0,uint8_t x1,uint8_t y1,uint8_t BMP[]);
void OLED_Printf(uint8_t x, uint8_t y, uint8_t str[], uint8_t size);
void OLED_Init(void);



#endif //__OLED_SPI_H
